<?php

class Jobvacations_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "jobs_vacation";
    }

    function insert($title, $companyid, $location, $qualification, $experience, $gender, $agemin, $agemax, $education, $salary, $note, $openuntil, $createddate, $createdby, $updateddate, $updatedby) {
        $dt = array("jv_title" => $title,
            "company_id" => $companyid,
            "jv_location" => $location,
            "jv_qualification" => $qualification,
            "jv_experience" => $experience,
            "jv_gender" => $gender,
            "jv_age_min" => $agemin,
            "jv_age_max" => $agemax,
            "jv_education" => $education,
            "jv_salary" => $salary,
            "jv_notes" => $note,
            "jv_expire_date" => $openuntil,
            "createddate" => $createddate,
            "createdby" => $createdby,
            "updateddate" => $updateddate,
            "updatedby" => $updatedby);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }

    function update($jobs_id, $dt, $where = "") {
        $this->db->where("jv_id", $jobs_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($jobs_id, $where = "") {
        $this->db->where("jv_id", $jobs_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($jobsid, $where = "") {
        $this->db->select("jobs_vacation.jv_id, jobs_vacation.jv_title, jobs_vacation.company_id, jobs_vacation.jv_location, jobs_vacation.jv_qualification, jobs_vacation.jv_experience, jobs_vacation.jv_gender, jobs_vacation.jv_age_min, jobs_vacation.jv_age_max, jobs_vacation.jv_education, jobs_vacation.jv_salary, jobs_vacation.jv_notes, company.company_name")
                ->from($this->tableName)
                ->join("company", "jobs_vacation.company_id = company.company_id");
        $this->db->where("jv_id", $jobsid);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row();
    }

    function getAll($startpage = "0", $perpage = "10", $where = "", $like = "", $orderby = "") {
        $this->db->select("jobs_vacation.jv_id, jobs_vacation.jv_title, jobs_vacation.company_id, jobs_vacation.jv_location, jobs_vacation.jv_qualification, jobs_vacation.jv_experience, jobs_vacation.jv_gender, jobs_vacation.jv_age_min, jobs_vacation.jv_age_max, jobs_vacation.jv_education, jobs_vacation.jv_salary, jobs_vacation.jv_notes, company.company_name")
                ->from($this->tableName)
                ->join("company", "jobs_vacation.company_id = company.company_id");
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($like != "")
            $this->db->like($like);
        if ($orderby != "")
            $this->db->order_by($orderby);
        return $this->db->get()->result();
    }

    function getAllCount($where = "", $like = "") {
        $this->db->select("COUNT(*) JUMLAH")
            ->from($this->tableName)
            ->join("company", "jobs_vacation.company_id = company.company_id");
        if ($like != "")
            $this->db->like($like);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row()->JUMLAH;
    }

}

?>